// Created by 11372 on 2021/12/27 14:44
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

/**
 * 执行用时：32 ms, 在所有 C++ 提交中击败了91.64%的用户
 * 内存消耗：36.3 MB, 在所有 C++ 提交中击败了92.24%的用户
 */
class Solution {
public:
    int numFriendRequests(vector<int> &ages) {
        int n = ages.size();
        int s[121] = {0};
        for (int i = 0; i < n; i++) s[ages[i]]++;
        int res = n * n;
        for (int i = 1; i <= 120; i++)
            for (int j = 1; j <= 120; j++)
                if (j <= 0.5 * i + 7 || j > i)
                    res -= s[i] * s[j];
                else if (i == j)
                    res -= s[i];
        return res;
    }
};

int main() {

    vector<int> ages = {16, 17, 18};
    cout << Solution().numFriendRequests(ages) << endl;  // 2

    return 0;
}
